package com.yiwangqingshui.jmx.main;

import com.yiwangqingshui.jmx.mbean.Hello;
import com.yiwangqingshui.jmx.notification.MyHelloNotificationlistener;

import javax.management.MBeanServer;
import javax.management.ObjectName;
import java.lang.management.ManagementFactory;

/**
 * @author smc
 * @date 2019-01-30 15:21
 * @since
 **/
public class HelloDemoMain {

    public static void main(String[] args) throws Exception {

        MBeanServer ms = ManagementFactory.getPlatformMBeanServer();

        ObjectName objectName = new ObjectName("com.yiwangqingshui:name=Hello");

        Hello hello = new Hello();

        ms.registerMBean(hello,objectName);

        MyHelloNotificationlistener helloNotificationlistener = new MyHelloNotificationlistener();

        ms.addNotificationListener(objectName,helloNotificationlistener,null,null);

        System.out.println(" init mbean init start keywords is end....");

        System.in.read();


    }

}
